fix: match real Perl error returns for tied filehandle I/O#350
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: match real Perl error returns for tied filehandle I/O#350toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
syswrite (WRITE) was returning 0 on error conditions where real Perl returns undef: EBADF on read-only handle, EINVAL for bad length/offset, and EBADF when mock data is destroyed. Similarly, sysread (READ) returned 0 instead of undef when mock data was gone. readline (READLINE) and getc (GETC) on write-only handles were missing $! = EBADF, which real Perl sets alongside the warning. Changes: - _write_bytes: return undef (not 0) on EBADF - WRITE: return undef on all error paths (EBADF, EINVAL) - READ: return undef (not 0) when mock data is destroyed - READLINE: set $! = EBADF on write-only handles - GETC: set $! = EBADF on write-only handles - New test t/fh_error_returns.t covering all corrected behaviors - Updated existing tests to expect undef instead of 0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Corrects return values and errno setting for tied filehandle error paths to match real Perl behavior.
Why
syswriteon a read-only handle (or with invalid args) returned0instead ofundef, making it indistinguishable from "wrote 0 bytes." Similarly,sysreadreturned0instead ofundefwhen the mock was destroyed (EBADF vs EOF).readlineandgetcon write-only handles warned correctly but didn't set$! = EBADF, diverging from real Perl.Code that checks
defined(syswrite(...))to detect errors would get false negatives.How
_write_bytes,WRITE,READ: returnundef(not0) on EBADF/EINVAL error pathsREADLINE,GETC: set$! = EBADFbefore returning on write-only handlesTesting
t/fh_error_returns.twith 7 subtests covering all corrected pathst/sysreadwrite_edge_cases.t,t/write_tell.t,t/filehandle_weakref.t,t/filehandle_cleanup.t,t/portability_errno.tto expectundefinstead of0fh-ref-leak.tfailure)🤖 Generated with Claude Code